package org.example;

import static java.util.stream.Collectors.toList;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

/**
 * @Title : StreamTest
 * @Description: :
 * @author: libo@juzishuke.com
 * @date: 2023/10/9 9:46
 * @Version:1.0
 */
public class StreamTest {

    /**
     * @param args :
     * @description: TODO
     * @return: void
     * @author: libo
     * @date: 2023/10/9
     **/
    public static void main(String[] args) {
        List<Integer> numbers1 = Arrays.asList(1, 2, 3);
        List<Integer> numbers2 = Arrays.asList(3, 4, 5);
        List<int[]> pairs = numbers1.stream()
                .flatMap(i -> numbers2.stream().map(j -> new int[]{i, j})).collect(toList());
        pairs.stream().forEach(e -> System.out.print(Arrays.toString(e)));
        System.out.println();
        List<Integer> numbers = Arrays.asList(1, 2, 3, 4);
        int sum = numbers.stream().reduce(1, (a, b) -> a * b);
        System.out.println(sum);

        Stream.iterate(new int[]{0, 1},
                        t -> new int[]{t[1], t[0]+t[1]})
                .limit(20)
                .forEach(t -> System.out.println("(" + t[0] + "," + t[1] +")"));
    }

}
